package com.cloud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by gang on 2019/6/28.
 */
@RestController
@RefreshScope
public class DemoController {
    @Value("${test}")
    String hello;

    @RequestMapping("/")
    public String Hello(HttpServletRequest request, HttpServletResponse response) {
        Cookie[] cookies = request.getCookies();
        System.out.println(cookies);
        Cookie cookie = new Cookie("majun", "xiaoya");
        cookie.setMaxAge(10); //设置cookie的过期时间是10s
        response.addCookie(cookie);
        return hello + " from" + request.getLocalPort();
    }
}
